#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <pthread.h>

#define MEM "mem.dat"
#define SIZE 40
#define SPART 100
#define MCOUNT 45

struct data{
	size_t n;
	off_t sz;
	int rl;
	struct data* next;
	struct data* last;
};

struct memory{
	void * st; 
	size_t n;
	};

struct sfile{
	int fd;
	off_t n;
	off_t free;
};

struct block{
	struct data** st;
	size_t* sz;
	size_t n;
};

//-------------------------------------------------------------------

struct thr1{
	struct data *one;
	off_t two;
	off_t three;
	};


struct thr2{
	struct data *one;
	off_t two;
	off_t three;
	off_t four;
	};

//---------------------------------------------------------------------

void * fsearch( void * tmp);
void clean( struct data* dis);
int id_free(struct data* dis, struct block tmp, size_t i);
void * fsearch_fr( void * tmp);	
size_t fadd(struct data* tmp, size_t sz, size_t id);	 
size_t middle( int* array, size_t n);
size_t prepare1( struct block tmp);

struct thr2* search(size_t id, struct block thr_block);
 
size_t add(size_t sz, struct block thr_block, size_t id);	
